<template>
  <div>
    <!-- <el-input
      clearable
      placeholder="输入关键字进行过滤"
      v-model="filterText">
    </el-input> -->
    <el-scrollbar class="scrollbarTree">
      <el-tree
        :indent="8"
        class="filter-tree"
        :highlight-current="highlightCurrent"
        :expand-on-click-node="false"
        check-on-click-node
        accordion
        node-key="id"
        :data="nodeTree"
        :props="defaultProps"
        :default-expand-all="false"
        :filter-node-method="filterNode"
        @node-click="handleNodeClick"
        v-bind="$attrs"
        v-on="$listeners"
        ref="deviceTree"
        :lazy="true"
        :load="loadDeviceNodeTree">
      </el-tree>
    </el-scrollbar>
  </div>
</template>

<script>
  export default {
    name: "deviceTree",
    props: {
      nodeTree: {
        type: Array
      },
      handleNodeClick: {
        type: Function
      },
      highlightCurrent: {
        type: Boolean,
        default:true
      },
      loadDeviceNodeTree:{
        type: Function
      }
    },
    data() {
      return {
        filterText: '',
        // nodeTree: [],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      }
    },
    watch: {
      filterText(val) {
        this.$refs.tree.filter(val);
      }
    },
    methods: {
      //节点过滤方法
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      }
    }
  }
</script>

<style scoped lang="scss">
  .scrollbarTree {
    height: calc(100vh - 230px);
    box-sizing: border-box;
    background-color: #ffffff;

    /deep/ .el-tree-node__label {
      padding-right: 16px;
    }

    /deep/ .el-tree-node > .el-tree-node__children {
      overflow: inherit;
    }
  }
</style>
